package softstarter.functionality;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;

public class ActionPerformer {

	ProcessExecutor processExecutor;
	
	public ActionPerformer() {
		processExecutor = new ProcessExecutor();
	}
	
	public boolean performActionFor(String pathToFile) {
		File file = new File(pathToFile);
		
		if(file.exists()) {
			System.out.println(pathToFile + " is existed.");
			if(file.canExecute()) 
				return launchApplication(file);
			else if(file.isFile())
				return launchApplication(file);
			else if(file.isDirectory())
				return launchApplication(file);
		} else {
			System.out.println(pathToFile + " is not existed.");
		}
		
		return false;
	}
	
    private boolean launchApplication(File file) {
        
        Desktop desktop = Desktop.getDesktop();
        
        try {
        	desktop.open(file);
        }
        catch (IOException ioe) {
            ioe.printStackTrace();
            return false;
        }
        
        return true;
    }

}
